package org.lalit.cvs;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Set;

public class CVSReader {
	private static EmployeeVO vo;

	public static void main(String[] args) throws FileNotFoundException,
			URISyntaxException {
		InputStream stream = CVSReader.class.getResourceAsStream("emp.csv");

		BufferedReader br = null;
		String line = "";
		String spliter = ",";
		Set<EmployeeVO> empVO = new HashSet<>();

		br = new BufferedReader(new InputStreamReader(stream));
		try {
			while ((line = br.readLine()) != null) {
				String[] emp = line.split(spliter);
				vo = new EmployeeVO();
				vo.setName(emp[0]);
				vo.setId(Integer.parseInt(emp[1]));
				vo.setSal(Double.parseDouble(emp[2]));
				vo.setAdd(emp[3]);
				empVO.add(vo);

			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		for (EmployeeVO vo : empVO) {
			System.out.println(vo.toString());
		}

	}

}
